// pages/msg.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    // 店铺信息
    shopMsg:{
      shopImg:'http://localhost:8080/shop/getShopImg/1',
      shopName:'',
      shopDescription:''
    },
    // 店铺轮播图图片
    img:[
      {id:1,url:'http://localhost:8080/shop/getActiveImg/1/1'},
      {id:2,url:'http://localhost:8080/shop/getActiveImg/1/2'},
      {id:3,url:'http://localhost:8080/shop/getActiveImg/1/3'},
    ],
    // 商家动态信息
    msg:[]
  },
  // 跳转事件
  toBuy(){
    wx.navigateTo({
      url: '/pages/index/index',
    })
  },
  // 生命周期，初始化数据
  onReady(){
    // 发送请求获取店铺名
    wx.request({
      url: 'http://localhost:8080/shop/getShopName/1',
      success:res=>{
        this.setData({'shopMsg.shopName':res.data})
      }
    })
    // 发送请求获取店铺简介
    wx.request({
      url: 'http://localhost:8080/shop/getShopDescription/1',
      success:res=>{
        this.setData({'shopMsg.shopDescription':res.data})
      }
    })
    // 发送请求获取店铺货物
    wx.request({
      url: 'http://localhost:8080/goods/getShopGoods',
      success:res=>{
        let products = []
        res.data.data.typeNames.forEach((element,index) => {
          products.push({
            type:element,
            goods:res.data.data.goods[index]
          })
        });
        this.setData({product:products})
      }
    })
    // 发送请求获取店铺动态
    wx.request({
      url: 'http://localhost:8080/shop/getShopMsg',
      success:res=>{
        let msgTemp = []
        console.log(res.data.data);
        res.data.data.shopMsgs.forEach(element => {
          msgTemp.push(element)
        })
        this.setData({msg:msgTemp})
      }
    })
  }
})